package com.xxgc.helloworld.aop;

import com.xxgc.helloworld.po.Info;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Aspect
@Slf4j
@PropertySource(value = "classpath:system.properties")
public class InfoAop {
    @Value("${system.version}")
    private String version;
    //切面方法 切点表达式
    @Around("execution(* com.xxgc.helloworld.controller.*.*(..))")
    public Object doAfter(ProceedingJoinPoint pjp)throws Throwable{
        log.info("获取到切面信息");
        //方法名
        String methodName = pjp.getSignature().getName();
        //执行目标方法
        Info result = (Info)pjp.proceed();
        result.setResponseDate(new Date());
        result.setVersion(version);
        log.info(result.toString());
        return result;

    }
}
